package cn.wolfcode.p2p.controller;


import cn.wolfcode.p2p.base.exception.CustomException;
import cn.wolfcode.p2p.util.JsonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理类
 */
@ControllerAdvice
public class CommonExceptionHandler {

    //自定义异常, 抛出异常信息传给JsonResult
    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public JsonResult customExceptionHandler(CustomException e){

        return JsonResult.instance(e.getMessage());

    }

    //统一异常
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public JsonResult exceptionHandler(Exception e){
        e.printStackTrace();
        return JsonResult.instance("努力抢修, 正在鞭策程序员中");
    }
}
